window.writeResult = new Vue({
    el: '#exerciseDetail',
    data() {
        return {
            isFull: false,//是否全屏
            count: 0,//总字数
            isSwitch: false,
            questionData: '',//题目数据
            content_id: '',//当前题目id
            time: '', sentsFeedback: [],
            majorScore: []
        }
    },
    created() {

    },
    mounted() {
        let that = this;
        that.getQuestion();

    },
    methods: {
        getQuestion() {//获取答案
            let that = this;
            $.get('/cn/exercise/get-write-result', {
                content_id: $('#content_id').val(),
            }, function (res) {
                if (res.code == 1) {
                    that.content_id = $('#content_id').val();
                    that.questionData = res;
                    that.time = that.formateSeconds(that.questionData.son[0].time);
                    var sentsFeedback = that.questionData.son[0].answerRemark.essayFeedback.sentsFeedback;
                    var arr = [];
                    for (var i = 0; i < sentsFeedback.length; i++) {

                        if (sentsFeedback[i].errorPosInfos.length > 0) {
                            var a=sentsFeedback[i]
                            arr.push(a)

                        }

                    }
                    that.sentsFeedback=arr
                    that.majorScore = that.questionData.son[0].answerRemark.majorScore;
                    console.log('sentsFeedback', sentsFeedback)
                    that.wordStatic(that.questionData.son[0].userAnswer);
                } else {
                    alert(res.message)
                }
            }, 'json')
        },
        //  统计英文单词数
        wordStatic(article) {
            let text = article.replace(/\r\n/g, " ").replace(/\n/g, " ").replace(/<[^>]+>/g, "");

            let arr = text.split(" ");
            for (var i = 0; i < arr.length; i++) {
                if (arr[i].length < 1) {
                    arr.splice(i, 1);
                    i = i - 1;
                }
            }
            this.count = arr.length;
        },
        //  全屏、退出全屏
        launchFullscreen() {
            let that = this;
            let element = document.documentElement;
            if (!that.isFull) {
                if (element.requestFullscreen) {
                    element.requestFullscreen();
                } else if (element.mozRequestFullScreen) {
                    element.mozRequestFullScreen();
                } else if (element.webkitRequestFullscreen) {
                    element.webkitRequestFullscreen();
                } else if (element.msRequestFullscreen) {
                    element.msRequestFullscreen();
                }
                that.isFull = true;
            } else {
                if (document.exitFullscreen) {
                    document.exitFullscreen();
                } else if (document.mozCancelFullScreen) {
                    document.mozCancelFullScreen();
                } else if (document.webkitExitFullscreen) {
                    document.webkitExitFullscreen();
                }
                that.isFull = false;
            }
        },
        //时间转换
        formateSeconds(endTime) {
            let secondTime = parseInt(endTime);//将传入的秒的值转化为Number
            let min = 0;// 初始化分
            let h = 0;// 初始化小时
            let result = '';
            if (secondTime > 60) {//如果秒数大于60，将秒数转换成整数
                min = parseInt(secondTime / 60);//获取分钟，除以60取整数，得到整数分钟
                secondTime = parseInt(secondTime % 60);//获取秒数，秒数取佘，得到整数秒数
                if (min > 60) {//如果分钟大于60，将分钟转换成小时
                    h = parseInt(min / 60);//获取小时，获取分钟除以60，得到整数小时
                    min = parseInt(min % 60);//获取小时后取佘的分，获取分钟除以60取佘的分
                }
            }
            result = `${h.toString().padStart(2, '00')}:${min.toString().padStart(2, '00')}:${secondTime.toString().padStart(2, '00')}`;
            return result;
        }
    }
});
